package com.example.task1.ui.AllService.movies;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.task1.R;
import com.example.task1.application.MyApplication;
import com.example.task1.bean.MoviesCinemaListBean;
import com.example.task1.ui.BaseAdapter;

import java.util.ArrayList;
import java.util.List;

public class MoviesCinemaAdapter extends BaseAdapter<MoviesCinemaListBean.RowsDTO> {

    private Context context;
    private List<MoviesCinemaListBean.RowsDTO> data = new ArrayList<>();
    private ImageView image;
    private TextView tvTitle;
    private TextView tvScore;
    private TextView tvAddress;
    private TextView tvAddressDetails;
    private TextView tvDistance;

    public MoviesCinemaAdapter(Context context) {
        this.context = context;
    }

    @Override
    protected void setData(List<MoviesCinemaListBean.RowsDTO> rows) {
        int size = data.size();
        data.addAll(rows);
        notifyItemInserted(size);
    }

    @Override
    protected int getLayout() {
        return R.layout.movieschinemalist;
    }

    @Override
    protected Context getContext() {
        return context;
    }

    @Override
    protected List<MoviesCinemaListBean.RowsDTO> getData() {
        return data;
    }

    @Override
    protected void onBind(myHolder holder, MoviesCinemaListBean.RowsDTO date) {
        MyApplication.glide(image, date.getCover());
        tvTitle.setText(date.getName());
        tvAddress.setText("地址：" + date.getProvince() + date.getCity() + date.getArea());
        tvAddressDetails.setText("详细地址：" + date.getProvince() + date.getCity() + date.getArea());
        tvDistance.setText("距离：" + date.getDistance());
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                MyApplication.intent(context, MoviesSelectFilmActivity.class, date.getId());
            }
        });
    }

    @Override
    protected void holder(View itemView) {
        initView(itemView);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public int getItemViewType(int position) {
        return position;
    }

    private void initView(View itemView) {
        image = (ImageView) itemView.findViewById(R.id.image);
        tvTitle = (TextView) itemView.findViewById(R.id.tv_title);
        tvScore = (TextView) itemView.findViewById(R.id.tv_score);
        tvAddress = (TextView) itemView.findViewById(R.id.tv_address);
        tvAddressDetails = (TextView) itemView.findViewById(R.id.tv_addressDetails);
        tvDistance = (TextView) itemView.findViewById(R.id.tv_distance);
    }
}
